package example.strategy.json;

import com.scop.desensitize.exception.strategy.DecodeException;
import com.scop.desensitize.exception.strategy.EncodeException;
import com.scop.desensitize.strategy.json.JsonObjStrategy;
import com.scop.desensitize.strategy.rreversible.symmetry.DesStrategy;
import org.apache.log4j.Logger;

import java.io.Serializable;

/**
 * @desc 实体对象转Json数据脱敏示例
 * @author gzy
 * @time 2022-05-01
 */
public class JsonObjStrategyDemo {
    public static Logger log = Logger.getLogger(JsonObjStrategyDemo.class);
    public static void main(String[] args) throws EncodeException, DecodeException {
        JsonObjStrategy jsonobj = new JsonObjStrategy(DesStrategy.getInstance());
        Student stu = new Student();
        Teacher teacher=new Teacher();
        teacher.setAge("18");
        teacher.setName("李四");
        teacher.setSex("男");
        stu.setName("张三");
        stu.setTeacher(teacher);

        Object sxx = jsonobj.encode(stu);
        Object obj = jsonobj.decode(sxx.toString());
        log.debug("元数据："+stu);
        log.debug("加密后数据："+sxx);
        log.debug("解密后数据："+obj);


    }

    public static class Student implements Serializable {
        private String name;

        private  Teacher teacher;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Teacher getTeacher() {
            return teacher;
        }

        public void setTeacher(Teacher teacher) {
            this.teacher = teacher;
        }

        @Override
        public String toString() {
            return "Student{" +
                    "name='" + name + '\'' +
                    ", teacher=" + teacher +
                    '}';
        }
    }

    public static class Teacher implements Serializable {
        private String name;
        private String sex;
        private  String age;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getSex() {
            return sex;
        }

        public void setSex(String sex) {
            this.sex = sex;
        }

        public String getAge() {
            return age;
        }

        public void setAge(String age) {
            this.age = age;
        }

        @Override
        public String toString() {
            return "Teacher{" +
                    "name='" + name + '\'' +
                    ", sex='" + sex + '\'' +
                    ", age='" + age + '\'' +
                    '}';
        }
    }
}
